#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
#include <time.h>
#include <memory.h>
#include <stdint.h>
#include <windows.h>

#define UINT8 uint8_t
#define MAP_SIZE 22
#define KEY_W 'w'
#define KEY_S 's'
#define KEY_A 'a'
#define KEY_D 'd'
typedef struct LinkedList
{
    //1 - 20
    UINT8 x;
    UINT8 y;
    struct LinkedList *next;
} Node, *PNode;

typedef enum
{
    UP = (UINT8)0B1001,
    LEFT = (UINT8)0B0011,
    RIGHT = (UINT8)0B0101,
    DOWN = (UINT8)0B1111
} Direction;

typedef enum
{
    LENGTHEN,
    REVERSE
} FruitType;

typedef struct
{
    UINT8 x;
    UINT8 y;
    FruitType type;
} Fruit, *PFruit;

void printStartUI();
void initMap(PNode snake, UINT8 size, UINT8 length);
PNode spawnSnake(UINT8 length, PNode *pTail);
PFruit spawnFruit(PNode snake);
void start(PNode snake);
void drawMap(PNode snake, char map[MAP_SIZE][MAP_SIZE], UINT8 size, PFruit fruit);
BOOL check(PNode snake, UINT8 size);
PNode findPreNode(PNode from, PNode target);
UINT8 moveNode(PNode *pSnake, PNode *pTail, Direction state, char map[MAP_SIZE][MAP_SIZE], PFruit *pFruit);

void moveUp(UINT8 *x, UINT8 *y);
void moveLeft(UINT8 *x, UINT8 *y);
void moveRight(UINT8 *x, UINT8 *y);
void moveDown(UINT8 *x, UINT8 *y);
void (*movePoint[4])(UINT8 *x, UINT8 *y) = {moveUp, moveLeft, moveRight, moveDown};

void dead();
void clrscr();
